With the addition of the 'disabled-extensions' key in commit
ce1bee727,
the way extensions are enabled/disabled changed: Now a UUID is always
added to one list and removed from another.
Prepare for that by generalizing the relevant bits of the existing
enable/disable commands as helper functions.
https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234
disable_extension (const char *uuid)
{
g_autoptr(GSettings) settings = get_shell_settings ();
- g_auto(GStrv) extensions = NULL;
- g_auto(GStrv) new_value = NULL;
- const char **s;
- guint n_extensions;
- int i;
if (settings == NULL)
return FALSE;
- if (!g_settings_is_writable (settings, "enabled-extensions"))
- return FALSE;
-
- extensions = g_settings_get_strv (settings, "enabled-extensions");
-
- if (!g_strv_contains ((const char **)extensions, uuid))
- return TRUE;
-
- n_extensions = g_strv_length (extensions);
- new_value = g_new0 (char *, n_extensions);
- for (i = 0, s = (const char **)extensions; i < n_extensions; i++, s++)
- if (!g_str_equal (*s, uuid))
- new_value[i] = g_strdup (*s);
-
- g_settings_set_strv (settings, "enabled-extensions", (const char **)new_value);
- g_settings_sync ();
-
- return TRUE;
+ return settings_list_remove (settings, "enabled-extensions", uuid);
}
int
enable_extension (const char *uuid)
{
g_autoptr(GSettings) settings = get_shell_settings ();
- g_auto(GStrv) extensions = NULL;
- g_auto(GStrv) new_value = NULL;
- guint n_extensions;
- int i;
if (settings == NULL)
return FALSE;
- if (!g_settings_is_writable (settings, "enabled-extensions"))
- return FALSE;
-
- extensions = g_settings_get_strv (settings, "enabled-extensions");
-
- if (g_strv_contains ((const char **)extensions, uuid))
- return TRUE;
-
- n_extensions = g_strv_length (extensions);
- new_value = g_new0 (char *, n_extensions + 2);
- for (i = 0; i < n_extensions; i++)
- new_value[i] = g_strdup (extensions[i]);
- new_value[i] = g_strdup (uuid);
-
- g_settings_set_strv (settings, "enabled-extensions", (const char **)new_value);
- g_settings_sync ();
-
- return TRUE;
+ return settings_list_add (settings, "enabled-extensions", uuid);
}
int
GDBusProxy *get_shell_proxy (GError **error);
GSettings *get_shell_settings (void);
+gboolean settings_list_add (GSettings *settings,
+ const char *key,
+ const char *value);
+gboolean settings_list_remove (GSettings *settings,
+ const char *key,
+ const char *value);
+
gboolean file_delete_recursively (GFile *file,
GError **error);
return g_settings_new_full (schema, NULL, NULL);
}
+gboolean
+settings_list_add (GSettings *settings,
+ const char *key,
+ const char *value)
+{
+ g_auto(GStrv) list = NULL;
+ g_auto(GStrv) new_value = NULL;
+ guint n_values;
+ int i;
+
+ if (!g_settings_is_writable (settings, key))
+ return FALSE;
+
+ list = g_settings_get_strv (settings, key);
+
+ if (g_strv_contains ((const char **)list, value))
+ return TRUE;
+
+ n_values = g_strv_length (list);
+ new_value = g_new0 (char *, n_values + 2);
+ for (i = 0; i < n_values; i++)
+ new_value[i] = g_strdup (list[i]);
+ new_value[i] = g_strdup (value);
+
+ g_settings_set_strv (settings, key, (const char **)new_value);
+ g_settings_sync ();
+
+ return TRUE;
+}
+
+gboolean
+settings_list_remove (GSettings *settings,
+ const char *key,
+ const char *value)
+{
+ g_auto(GStrv) list = NULL;
+ g_auto(GStrv) new_value = NULL;
+ const char **s;
+ guint n_values;
+ int i;
+
+ if (!g_settings_is_writable (settings, key))
+ return FALSE;
+
+ list = g_settings_get_strv (settings, key);
+
+ if (!g_strv_contains ((const char **)list, value))
+ return TRUE;
+
+ n_values = g_strv_length (list);
+ new_value = g_new0 (char *, n_values);
+ for (i = 0, s = (const char **)list; i < n_values; i++, s++)
+ if (!g_str_equal (*s, value))
+ new_value[i] = g_strdup (*s);
+
+ g_settings_set_strv (settings, key, (const char **)new_value);
+ g_settings_sync ();
+
+ return TRUE;
+}
+
void
print_extension_info (GVariantDict *info,
DisplayFormat format)